package com.guldan.jaina.provider;

import com.guldan.core.constants.CommonConstant;
import com.guldan.core.dubbo.client.ResponseDTO;
import com.guldan.core.utils.DateUtil;
import com.guldan.jaina.dto.datastat.datav.DatavDTO;
import com.guldan.jaina.dto.datastat.home.*;
import com.guldan.jaina.dto.datastat.report.MoneyStatDTO;
import com.guldan.jaina.dto.datastat.report.ReportSearchDTO;
import com.guldan.jaina.dto.datastat.report.SubsidyGrantStatDTO;
import com.guldan.jaina.dto.report.Points;
import com.guldan.jaina.dto.report.project.ProjectSearchDTO;
import com.guldan.jaina.manager.ReportManager;
import com.guldan.jaina.utils.UserUtils;
import com.guldan.mapper.db.mapper.DataStatMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Silas.
 * Date: 2016/12/11
 * Time: 22:51
 */
@Component
public class ReportProviderImpl implements IReportProvider {

    @Autowired
    private ReportManager reportManager;

    @Autowired
    private DataStatMapper dataStatMapper;

    @Override
    public ResponseDTO<List<Points>> projectMoneyStat(ProjectSearchDTO searchDTO) {
        ResponseDTO<List<Points>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.projectMoneyStat(searchDTO));
        return responseDTO;
    }

    //获取首页快捷导航
    @Override
    public ResponseDTO<List<HomeQuickNavDTO>> getHomeQuickNavList() {
        ResponseDTO<List<HomeQuickNavDTO>> responseDTO = new ResponseDTO<>();
        List<HomeQuickNavDTO> list = new ArrayList<>();
        List<String[]> tt = new ArrayList<>();

        switch (UserUtils.getUser().getUserRole()) {
            case CommonConstant.ROLE_TownsEntry:
                tt.add(new String[]{"补贴录入", "/projectRegister/townsRegistingList"});
                tt.add(new String[]{"补贴查看", "/projectRegister/townsRegistedList"});
                tt.add(new String[]{"人员管理", "/citizen/list"});
                tt.add(new String[]{"快速查询", "/projectRegister/registerList"});
                break;
            case CommonConstant.ROLE_TownsReview:
                tt.add(new String[]{"补贴复核", "/projectRegister/townsAuditoringList"});
                tt.add(new String[]{"补贴查看", "/projectRegister/townsAuditoredList"});
                tt.add(new String[]{"人员管理", "/citizen/list"});
                tt.add(new String[]{"快速查询", "/projectRegister/registerList"});
                break;
            case CommonConstant.ROLE_Org:
                tt.add(new String[]{"补贴审批", "/projectRegister/orgAuditorList"});
                tt.add(new String[]{"补贴查看", "/projectRegister/orgBatchSummaryList"});
                tt.add(new String[]{"清单查看", "/projectRegister/listCitizen"});
                tt.add(new String[]{"快速查询", "/projectRegister/registerList"});
                break;
            case CommonConstant.ROLE_Finance:
                tt.add(new String[]{"补贴审批", "/projectRegister/financeAuditorList"});
                tt.add(new String[]{"补贴查看", "/projectRegister/financeAuditoredSummaryBatchList"});
                tt.add(new String[]{"代发生成", "/projectRegister/financeAuditoredSummaryBatchList"});
                tt.add(new String[]{"回执上传", "/projectRegister/financeAuditoredSummaryBatchList"});
                break;
            default:
                break;
        }

        for (String[] t : tt) {
            HomeQuickNavDTO dto = new HomeQuickNavDTO(t[0], t[1]);
            list.add(dto);
        }

        responseDTO.setData(list);

        return responseDTO;
    }

    //首页顶部一行统计
    @Override
    public ResponseDTO<Part1DTO> getPart1DTO() {
        ResponseDTO<Part1DTO> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getPart1DTO());
        return responseDTO;
    }


    @Override
    public ResponseDTO<Part2DTO> getPart2DTO() {
        ResponseDTO<Part2DTO> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getPart2DTO());
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<BatchRegistStatDTO>> getBatchRegistStatByDate(Integer searchType, String dateBegin, String dateEnd) {
        ResponseDTO<List<BatchRegistStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getBatchRegistStatByDate(searchType, dateBegin, dateEnd));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<HotProjectStatDTO>> getHotProjectStatList() {
        ResponseDTO<List<HotProjectStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getHotProjectStatList());
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<MoneyStatDTO>> getMoneyStat(ReportSearchDTO searchDTO) {
        ResponseDTO<List<MoneyStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getMoneyStat(searchDTO));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<SubsidyGrantStatDTO>> getPersonStat(ReportSearchDTO searchDTO) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getPersonStat(searchDTO));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<SubsidyGrantStatDTO>> getSubsidyGrantStatForArea(ReportSearchDTO searchDTO) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getSubsidyGrantStatForArea(searchDTO));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<SubsidyGrantStatDTO>> getSubsidyGrantStatForProject(ReportSearchDTO searchDTO) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getSubsidyGrantStatForProject(searchDTO));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<SubsidyGrantStatDTO>> getGenderStat(ReportSearchDTO searchDTO) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getGenderStat(searchDTO));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<SubsidyGrantStatDTO>> getNationStat(ReportSearchDTO searchDTO) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getNationStat(searchDTO));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<SubsidyGrantStatDTO>> getBenefitAgeStat(ReportSearchDTO searchDTO) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getBenefitAgeStat(searchDTO));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<SubsidyGrantStatDTO>> getGenderStatForCitzen(ReportSearchDTO searchDTO) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getGenderStatForCitzen(searchDTO));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<SubsidyGrantStatDTO>> getNationStatForCitzen(ReportSearchDTO searchDTO) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getNationStatForCitzen(searchDTO));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<SubsidyGrantStatDTO>> getAgeStatForCitzen(ReportSearchDTO searchDTO) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getAgeStatForCitzen(searchDTO));
        return responseDTO;
    }

    @Override
    public ResponseDTO<List<SubsidyGrantStatDTO>> getAreaPersonStatForCitzen(ReportSearchDTO searchDTO) {
        ResponseDTO<List<SubsidyGrantStatDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(reportManager.getAreaPersonStatForCitzen(searchDTO));
        return responseDTO;
    }

    @Override
    public ResponseDTO<DatavDTO> getDatavDTO(Integer areaId) {

        ResponseDTO<DatavDTO> responseDTO = new ResponseDTO<>();
        DatavDTO datavDTO = reportManager.getDatavDTO(areaId, true);

        responseDTO.setData(datavDTO);
        return responseDTO;
    }

    @Override
    public ResponseDTO<DatavDTO> getDatavDTO(String divisionCode) {

        ResponseDTO<DatavDTO> responseDTO = new ResponseDTO<>();
        DatavDTO datavDTO = reportManager.getDatavDTO(divisionCode, true);

        responseDTO.setData(datavDTO);
        return responseDTO;
    }
}
